#!/usr/bin/python
# -*- coding: utf-8 -*-
from Tkinter import*
chtv = False
pol = False
pol3 = False
vosm = False
tri = False
posx = range(5,780,21)
i = 0
x = 0
def save():
	can.postscript(file = "out.ps")
def stan():
	global line
	i = 0
	while i < 5:
		can.create_line(0,line,740,line)
		line = line + 10
		i = i + 1
def callback(event):
	global px,line,i,x
	if event.y % 5 == 1:
		event.y = event.y - 1
	if event.y % 5 == 2:
		event.y = event.y - 2
	if event.y % 5 == 3:
		event.y = event.y - 3
	if event.y % 5 == 4:
		event.y = event.y - 4
	if event.y % 5 == 0:
		if vosm == True:
			can.create_oval(posx[x],event.y-5,posx[x]+10,event.y+5,fill = "black")
			can.create_line(posx[x]+10,event.y,posx[x]+10,event.y-40)
			can.create_line(posx[x]+10,event.y-40,posx[x]+15,event.y-20)
			i = i + 0.5
			x = x + 1
		if chtv == True:
			can.create_oval(posx[x],event.y-5,posx[x]+10,event.y+5,fill = "black")
			can.create_line(posx[x]+10,event.y,posx[x]+10,event.y-40)
			i = i + 1
			x = x + 1
		if pol == True:
			can.create_oval(posx[x],event.y-5,posx[x]+10,event.y+5)
			can.create_line(posx[x]+10,event.y,posx[x]+10,event.y-40)
			i = i + 2
			x = x + 1
		if pol3 == True:
			can.create_oval(posx[x],event.y-5,posx[x]+10,event.y+5)
			can.create_oval(posx[x]+15,event.y-1,posx[x]+17,event.y+1,fill = "black")
			can.create_line(posx[x]+10,event.y,posx[x]+10,event.y-40)
			i = i + 3
			x = x + 1
		if tri == True:
			if i == 3 or i == 6 or i == 9 or i == 12 or i == 15 or i == 18 or i == 21 or i == 24 or i == 27 or i == 30 or i == 33:
				can.create_line(posx[x]+10,line-10,posx[x]+10,line-50)
				x = x + 1
		else:
			if i == 4 or i == 8 or i == 12 or i == 16 or i == 20 or i == 24 or i == 28 or i == 32 or i == 36 or i == 40 or i == 44:
				can.create_line(posx[x]+10,line-10,posx[x]+10,line-50)
				x = x + 1
	if posx[x] > 735:
		x = 0
		i = 0
		line = line + 100
		stan()
root = Tk()
can = Canvas(root,width = 740,height = 700)	
can.pack()
can.bind("<Button-1>", callback)
can.pack()
line = 100
stan()
while True:
	inp = raw_input("введите длительность ноты: 2,  4 , 8************************razmer 3/4 4/4: ")
	if inp == "razmer":
		inp1 = raw_input("vvedite razmer 3/4 4/4: ")
		if inp1 == "3/4":
			tri = True
		else:
			print "error razmer"
		continue
	elif inp == "8":
		vosm = True
		pol = False
		chtv = False
		pol3 = False
	elif inp == "4":
		chtv = True
		pol = False
		vosm = False
		pol3 = False
	elif inp == "2":
		pol = True
		chtv = False
		pol3 = False
		vosm = False
	elif inp == "2.":
		pol3 = True
		chtv = False
		vosm = False
		chtv = False
	elif inp == "q":
		break
	elif inp == "s":
		save()
root.mainloop()  
